common={
	initCatalogueMagePage:function(){
		this.Authorization= window.localStorage.getItem("auth_token") || '';
		// 绑定dom对象
		this.obj = {
			searchText:$('#searchText'),
		};
		// 声明全局变量
		this.vars = {
			datatable:[],
			searchTable:{
				areaId:"",
                platformName:"",
                owersName:"",
				vehicleNo:"",
				transType:"",
				vehicleColor:"",
				vInCode:"",
                startTime:"",
                endTime:"",
				networkVeh:"",
				onlineVeh:"",
				uplineVeh:"",
				notNetworkVeh:"",
				monthOnlineVeh:"",
				otherProvincesVeh:"",
				page:1,
				size:10,
			},
		};
		// 通过首页传参
		this.getUrlParams();
		this.diquSelceted();
		this.time();
		this.selectedValue();
		this.btnEvent();
	},
	getUrlParams() {
		let hash = window.location.hash
		if (hash.indexOf('?index=') > 0) {
			let index = hash.split('?index=')[1]
			if(index==1){
				this.chongzhisearch();
				this.vars.searchTable.networkVeh="1";
				$(".search-div .rtable_button input").eq(0).addClass('active').siblings('input').removeClass('active')
			}else if(index==2){
				this.chongzhisearch();
				this.vars.searchTable.networkVeh="1";
				$(".search-div .rtable_button input").eq(0).addClass('active').siblings('input').removeClass('active')
			}else if(index==3){
				// 当月上线
				this.chongzhisearch();
				this.vars.searchTable.monthOnlineVeh="1";
				$(".search-div .rtable_button input").eq(4).addClass('active').siblings('input').removeClass('active')
			}else if(index==4){
				this.chongzhisearch();
				this.vars.searchTable.uplineVeh="1";
				$(".search-div .rtable_button input").eq(2).addClass('active').siblings('input').removeClass('active')
			}else if(index==5){
				this.chongzhisearch();
				this.vars.searchTable.onlineVeh="1";
				$(".search-div .rtable_button input").eq(1).addClass('active').siblings('input').removeClass('active')
			}
			this.ajaxtable(this.vars.searchTable);
		} else {
			this.ajaxtable(this.vars.searchTable);
		}

	},
	diquSelceted:function(){

		var self=this;
		var mapurl=HTTP+urls.diquSelceted;
		console.log(mapurl)
		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			url: mapurl,
			type: "get",
			success: function (data) {
				console.log(data);
				data[0].code=1;
				$.each(data[0].cityAreaVOS,function(i,dom){
					data[0].cityAreaVOS[i].code=2;
					$.each(data[0].cityAreaVOS[i].cityAreaVOS,function(j,dom){
						data[0].cityAreaVOS[i].cityAreaVOS[j].code=3;
					})
				})
				self.creatMainRido("qrm-main",data,"cityAreaVOS","code");
			}
		});

	},
	creatMainRido:function(id,attr,child,jibie){
		$(id).html("");
		var sttrdiv="";
		for(var i=0;i<3;i++){
			sttrdiv +="<div class='qrm-border"+(i+1)+"' style='display:none'>"+
				"<ul class='qrm-lev-"+(i+1)+" qrm-lev' id='qrm-border1'>"+
				"</ul>"+
				"</div>"
		};
		$(".qrm-main").html(sttrdiv);
		var str="";
		$("#qrm-border1").html("");
		var forTree = function(o){
			for(var i=0;i<o.length;i++){
				var urlstr = "";
				try{
					urlstr = "<li><span data-id='"+o[i]["id"]+"'>"+ o[i]["name"] +"</span><i class='qrm-arrow-right'></i><ul class='li-zi-"+o[i][jibie]+"' style='display: none'>";
					str += urlstr;
					if(o[i][child] != null){
						forTree(o[i][child]);
					}
					str += "</ul>";
				}catch(e){}
			}
			return str;
		};
		$("#qrm-border1").html(forTree(attr));
	},
	tableEvent:function(id,data,columns,paginationShow,total){
		var self=this;
		$('#' + id).bootstrapTable({
			method: 'get',
			cache: false,
			height: 430,
			pagination: paginationShow,
			pageSize: self.vars.searchTable.size,
			pageNumber:self.vars.searchTable.page,
			showColumns: true,
			striped: true,
			columns: columns,
			data :data,
			sidePagination: 'server',
			totalRows: total,
			onPageChange: function (size, number) {
				console.log(size)
				console.log(number)
				self.vars.searchTable.size=size;
				self.vars.searchTable.page=number;
				self.ajaxtable()
			},
			formatNoMatches: function(){
				return '无符合条件的记录';
			}
		});
	},
	creatTable:function(res){
		var self=this;
		var columnsOne = [
			{
				field: 'id',
				title: '序号',
				align: 'center',
				formatter: function (value, row, index) {
					var pageSize=self.vars.searchTable.size;
					var pageNumber=self.vars.searchTable.page;
					return pageSize * (pageNumber - 1) + index + 1;
				}
			},
			{
				field: 'vehicleNo',
				title: '车牌号',
			},
			{
				field: 'areaName',
				title: '地区',
			},
			{
				field: 'platformName',
				title: '平台',
			},
			{
				field: 'owersName',
				title: '企业',
			},
			{
				field: 'vehicleColor',
				title: '车牌颜色',
			},
			{
				field: 'transTypeName',
				title: '运输行业类型',
			},
			{
				field: 'vehicleTypeName',
				title: '车辆类型',
			},
			{
				field: 'terminalNo',
				title: '车辆定位终端型号',
			},
			{
				field: 'vInCode',
				title: '车辆识别VIN码',
			},
			{
				field: 'createTime',
				title: '创建时间',
			}
		];
		self.tableEvent("check_detail",res.data,columnsOne,true,res.total);
	},
	ajaxtable:function(){
		var self=this;
		jrequest.get(urls.car,self.vars.searchTable).then(res => {
			console.log("123",res)
			self.vars.datatable = res.data;
			$('#check_detail').bootstrapTable('destroy');
			self.creatTable(res)
		})
	},
	btnEvent:function(){
		var self=this;
		$(".search-div .j-search-btn button").eq(0).unbind("click");
		$(".search-div .j-search-btn button").eq(0).click(function(){
			self.vars.searchTable.areaId=$(".j-search-rowount .item").eq(0).find("input").attr("data-id");
			self.vars.searchTable.platformName=$(".j-search-rowount .item").eq(1).find("input").val();
			self.vars.searchTable.owersName=$(".j-search-rowount .item").eq(2).find("input").val();
			self.vars.searchTable.vehicleNo=$(".j-search-rowount .item").eq(3).find("input").val();
            var num=$("#selcet1").find("option:selected").index();
            if(num==0){
                self.vars.searchTable.transType="";
            }else{
                self.vars.searchTable.transType=num;
            }
			var numColor=$("#selcet2").find("option:selected").index();
			if(numColor==0){
				self.vars.searchTable.vehicleColor="";
			}else{
				self.vars.searchTable.vehicleColor=numColor;
			}
			self.vars.searchTable.vInCode=$(".rain_topden1 .item").eq(1).find("input").val();
			self.vars.searchTable.page=1;
			self.vars.searchTable.size=10;
			self.ajaxtable()
		});
		$(".search-div .j-search-btn button").eq(1).unbind("click");
		$(".search-div .j-search-btn button").eq(1).click(function(){
			self.chongzhi();
			self.vars.searchTable.areaId="";
			self.vars.searchTable.platformName="";
			self.vars.searchTable.owersName="";
			self.vars.searchTable.vehicleNo="";
			self.vars.searchTable.transType="";
			self.vars.searchTable.vehicleColor="";
			self.vars.searchTable.startTime="";
			self.vars.searchTable.endTime="";
			self.vars.searchTable.page=1;
			self.vars.searchTable.size=10;
			self.ajaxtable()
		});
		$(".search-div .rtable_button input").unbind("click");
		$(".search-div .rtable_button input").click(function(){
			$(this).addClass('active').siblings('input').removeClass('active')
			var index=$(this).index();
			if(index==1){
				self.chongzhisearch();
				self.vars.searchTable.networkVeh="1"
			}else if(index==2){
				self.chongzhisearch();
				self.vars.searchTable.onlineVeh="1"
			}else if(index==3){
				self.chongzhisearch();
				self.vars.searchTable.uplineVeh="1"
			}else if(index==4){
				self.chongzhisearch();
				self.vars.searchTable.notNetworkVeh="1"
			}else if(index==5){
				self.chongzhisearch();
				self.vars.searchTable.monthOnlineVeh="1"
			}else{
				self.chongzhisearch();
				self.vars.searchTable.otherProvincesVeh="1"
			}
			if($(".rain_topden1").is(":hidden")){
				var height=$(".table-con").height()-268;
			}else{
				var height=$(".table-con").height()-322;
			}
			self.ajaxtable(self.vars.searchTable,height)
		});
		$(".search-div .j-search-btn button").eq(2).unbind("click");
		$(".search-div .j-search-btn button").eq(2).click(function(){

			if($(".rain_topden1").is(":hidden")){
				$(".rain_topden1").show();
				var height=$(".table-con").height()-312;
			}else{
				$(".rain_topden1").hide();
				var height=$(".table-con").height()-268;
			}
			self.ajaxtable(self.vars.searchTable,height)
		})

	},
	chongzhisearch:function(){
		var self=this;
		self.vars.searchTable.areaId="";
		self.vars.searchTable.platformName="";
		self.vars.searchTable.owersName="";
		self.vars.searchTable.vehicleNo="";
		self.vars.searchTable.transType="";
		self.vars.searchTable.vehicleColor="";
		self.vars.searchTable.vInCode="";
		self.vars.searchTable.timeStart="";
		self.vars.searchTable.timeEnd="";
		self.vars.searchTable.networkVeh="";
		self.vars.searchTable.onlineVeh="";
		self.vars.searchTable.uplineVeh="";
		self.vars.searchTable.notNetworkVeh="";
		self.vars.searchTable.monthOnlineVeh="";
		self.vars.searchTable.otherProvincesVeh="";
		self.vars.searchTable.page=1;
		self.vars.searchTable.size=10;
    },
	chongzhi:function(){
		$(".j-search-rowount .item").eq(0).find("input").val("");
		$(".j-search-rowount .item").eq(0).find("input").attr("data-id","");
		$(".j-search-rowount .item").eq(1).find("input").val("");
		$(".j-search-rowount .item").eq(2).find("input").val("");
		$(".j-search-rowount .item").eq(3).find("input").val("");
		$("#selcet1").siblings("input").val("全部");
		$("#selcet2").siblings("input").val("全部");
		$(".rain_topden1 .item").eq(1).find("input").val("");
		$('#time_fn').find("input").val("");
	},
	time:function(){
        var self=this;
		$('#time_fn').datePicker({
			format: 'YYYY-MM-DD HH:mm',
			isRange: true,
			hide: function () {
				self.vars.searchTable.startTime=this.$input.eq(0).val();
				self.vars.searchTable.endTime=this.$input.eq(1).val();
			}
		});
	},
	selectedValue:function(){
		var self=this;
		var optionArr=["全部","班车客运","旅游包车","危险品运输"];
		self.creatId("#selcet1",optionArr);
		var optionArr1=["全部","蓝色","黄色","黑色","白色","其他"];
		self.creatId("#selcet2",optionArr1);
	},
	creatId:function(id,optionArr){
		$(id).html();
		var str="";
		$.each(optionArr,function (i) {
			str+="<option value='"+optionArr[i]+"'>"+optionArr[i]+"</option>"
		});
		$(id).html(str);
		$(id).comboSelect();
	},

}

$(function(){
	common.initCatalogueMagePage();
});
